//
//  ProductNameAndSloganList.m
//  MexicoLoan
//
//  Created by WXP on 2025/3/11.
//
//

#import "ProductNameAndSloganList.h"

NSString *const kProductNameAndSloganListAmount = KEY_amount;
NSString *const kProductNameAndSloganListProductName = KEY_productName;
NSString *const kProductNameAndSloganListProductId = KEY_productId;
NSString *const kProductNameAndSloganListSlogan = KEY_slogan;

@interface ProductNameAndSloganList ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ProductNameAndSloganList

@synthesize amount = _amount;
@synthesize productName = _productName;
@synthesize productId = _productId;
@synthesize slogan = _slogan;

+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
        self.amount = [[self objectOrNilForKey:kProductNameAndSloganListAmount fromDictionary:dict] doubleValue];
        self.productName = [self objectOrNilForKey:kProductNameAndSloganListProductName fromDictionary:dict];
        self.productId = [[self objectOrNilForKey:kProductNameAndSloganListProductId fromDictionary:dict] doubleValue];
        self.slogan = [self objectOrNilForKey:kProductNameAndSloganListSlogan fromDictionary:dict];
    }
    return self;
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.amount] forKey:kProductNameAndSloganListAmount];
    [mutableDict setValue:self.productName forKey:kProductNameAndSloganListProductName];
    [mutableDict setValue:[NSNumber numberWithDouble:self.productId] forKey:kProductNameAndSloganListProductId];
    [mutableDict setValue:self.slogan forKey:kProductNameAndSloganListSlogan];
    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}

@end
